package leetcode.code0926;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

//执行用时：8 ms, 在所有 Java 提交中击败了88.70%的用户
//
//内存消耗：42.6 MB, 在所有 Java 提交中击败了21.92%的用户
//
//通过测试用例：93 / 93
public class Solution implements IDebug {

	public int minFlipsMonoIncr(String s) {
		int len = s.length();
		char[] cs = s.toCharArray();
		int zero = 0, one = 0;
		int cZero, cOne;
		for (int i = 0; i < len; i++) {
			if (cs[i] == '0') {
				cZero = zero;
				cOne = Math.min(zero, one) + 1;
			} else {
				cZero = zero + 1;
				cOne = Math.min(zero, one);
			}
			zero = cZero;
			one = cOne;
		}
		return Math.min(zero, one);
	}

	@Override
	public void debug1() {
		HelpDebug.compare(1, this.minFlipsMonoIncr("00110"));
	}

	@Override
	public void debug2() {
		HelpDebug.compare(2, this.minFlipsMonoIncr("010110"));

	}

	@Override
	public void debug3() {
		HelpDebug.compare(2, this.minFlipsMonoIncr("00011000"));

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
